﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using HR.Appointments.Service.DisplayLists;
using HR.Appointments.Service.ValueObjects;

namespace HR.Appointments.Service.Test
{
    [TestFixture]
    public class TestCalender
    {
        [SetUp]
        public void SetUp()
        {
            MockDao.SetUp();
        }

        [TearDown]
        public void TearDown()
        {
            MockDao.TearDown();
        }

        [Test]
        public void OpenCalender()
        {
            CalendarBook cal = CalendarBook.Open(1, TestVariables.Date);
            Assert.IsNotNull(cal);
        }

        [Test]
        public void OpenSlots()
        {
            CalendarBook cal = CalendarBook.Open(1, TestVariables.Date);
            Assert.IsNotNull(cal);

            List<TimeList> result = cal.GetOpenHours();
            Assert.AreEqual(18, result.Count);
        }

        [Test]
        public void GetReservedSlots()
        {
            CalendarBook cal = CalendarBook.Open(1,TestVariables.Date);
            Assert.IsNotNull(cal);

            List<TimeList> result = cal.GetReservedSlots(1);
            Assert.AreEqual(27, result.Count);

            result = cal.GetReservedSlots(2);
            Assert.AreEqual(1, result.Count);
        }

        [Test]
        public void GetBookedSlots()
        {
            CalendarBook cal = CalendarBook.Open(1, TestVariables.Date);
            Assert.IsNotNull(cal);

            List<TimeList> result = cal.GetBookedSlots(1);
            Assert.AreEqual(4, result.Count);
        }

        [Test]
        public void GetOrderedSlots()
        {
            CalendarBook cal = CalendarBook.Open(1, TestVariables.Date);
            Assert.IsNotNull(cal);

            List<TimeList> result = cal.GetOrderedSlots(1);
            Assert.AreEqual(2, result.Count);
        }

        [Test]
        public void GetVacantSlot()
        {
            var activity = DAO.Instance.Activity.GetInstance(1);
            Assert.AreEqual(60, activity.Duration);

            CalendarBook cal = CalendarBook.Open(1, TestVariables.Date);
            Assert.IsNotNull(cal);

            List<TimeList> vacantSlots = cal.GetVacantSlots(1, 1);
            Assert.AreEqual(3, vacantSlots.Count);

            //BEG:Old test without activity duration.
            //Assert.AreEqual(5, vacantSlots.Count);

            //Assert.AreEqual(TimeUnit.Create(13, 30).ToString(), vacantSlots[0].Time);
            //Assert.AreEqual(TimeUnit.Create(15, 0).ToString(), vacantSlots[1].Time);
            //Assert.AreEqual(TimeUnit.Create(15, 30).ToString(), vacantSlots[2].Time);
            //Assert.AreEqual(TimeUnit.Create(16, 0).ToString(), vacantSlots[3].Time);
            //Assert.AreEqual(TimeUnit.Create(16, 30).ToString(), vacantSlots[4].Time);
            //END:Old test without activity duration.

            Assert.AreEqual(TimeUnit.Create(15, 0).ToString(), vacantSlots[0].Time);
            Assert.AreEqual(TimeUnit.Create(15, 30).ToString(), vacantSlots[1].Time);
            Assert.AreEqual(TimeUnit.Create(16, 0).ToString(), vacantSlots[2].Time);

            vacantSlots = cal.GetVacantSlots(2, 1);
            Assert.AreEqual(15, vacantSlots.Count);
        }
    }
}
